package com.qa.dom.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.qa.dom.dto.HomePageDto;
import com.qa.dom.dto.TeacherDetailDto;
import com.qa.dom.dto.UsertableDto;
import com.qa.dom.entity.Param;
import com.qa.dom.mapper.UsertableMapper;
import com.qa.dom.entity.Usertable;
import com.qa.dom.service.IUsertableService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 用户表 服务实现类
 * </p>
 *
 * @author cxj
 * @since 2018-04-24
 */
@Service
public class UsertableServiceImpl extends ServiceImpl<UsertableMapper, Usertable> implements IUsertableService {

    @Resource
    UsertableMapper mapper;
    @Override
    public List<HomePageDto> queryHomePage(Usertable usertable) {
        return mapper.queryHomePage(usertable);
    }

    @Override
    public Page<HomePageDto> queryHomePageByPage(Page<HomePageDto> page , Usertable usertable) {
        List<HomePageDto> list= mapper.queryHomePageByPage(page,usertable);
        page.setRecords(list);
        page.setTotal(list.size());
        return page;
    }




    @Override
    public TeacherDetailDto queryTeacher(Usertable usertable,Integer teacherId) {
        return mapper.queryTeacher(usertable,teacherId);
    }


    @Override
    public boolean updateStuNickname(Integer id, String nickname) {
        try {
            mapper.updateStuNickname(id,nickname);
            return true;
        } catch (Exception e) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();//进行手动回滚操作。
            e.printStackTrace();
            return false;
        }
    }

    @Override
    public boolean updateStuImg(Integer id, String sheadimg) {
        try {
            mapper.updateStuImg(id,sheadimg);
            return true;
        } catch (Exception e) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();//进行手动回滚操作。
            e.printStackTrace();
            return false;
        }
    }

    @Override
    public UsertableDto queryUsertableById(Integer id) {
        return mapper.queryUsertableById(id);
    }

    @Override
    public Param queryGrade(String phone) {
        return mapper.queryGrade(phone);
    }


}
